package com.zenith.edu.controller;

import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.Result;
import com.zenith.edu.po.dto.EduWarningLogDTO;
import com.zenith.edu.po.vo.EduWarningLogVO;
import com.zenith.edu.service.EduWarningLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/edu/warning-log")
@Tag(name = "预警日志管理", description = "预警日志管理接口")
public class EduWarningLogController {
    
    @Autowired
    private EduWarningLogService eduWarningLogService;
    
    @SecurePostMapping(value = "/createWarningLog", roles = "ROLE_ADMIN", permission = "warning-log:create")
    @Operation(summary = "创建预警日志")
    public Result<EduWarningLogVO> createWarningLog(@RequestBody EduWarningLogDTO dto) {
        EduWarningLogVO warningLogVO = eduWarningLogService.createWarningLog(dto);
        return Result.success(warningLogVO);
    }
    
    @SecurePostMapping(value = "/getWarningLogById/{id}", roles = "ROLE_ADMIN", permission = "warning-log:read")
    @Operation(summary = "根据ID获取预警日志详情")
    public Result<EduWarningLogVO> getWarningLogById(@PathVariable Long id) {
        EduWarningLogVO warningLogVO = eduWarningLogService.getWarningLogById(id);
        if (warningLogVO == null) {
            return Result.fail("预警日志不存在");
        }
        return Result.success(warningLogVO);
    }
    
    @SecurePostMapping(value = "/updateWarningLog", roles = "ROLE_ADMIN", permission = "warning-log:update")
    @Operation(summary = "更新预警日志信息")
    public Result<EduWarningLogVO> updateWarningLog(@RequestBody EduWarningLogDTO dto) {
        EduWarningLogVO warningLogVO = eduWarningLogService.updateWarningLog(dto);
        return Result.success(warningLogVO);
    }
    
    @SecurePostMapping(value = "/deleteWarningLog/{id}", roles = "ROLE_ADMIN", permission = "warning-log:delete")
    @Operation(summary = "删除指定预警日志")
    public Result<Void> deleteWarningLog(@PathVariable Long id) {
        boolean result = eduWarningLogService.deleteWarningLog(id);
        if (!result) {
            return Result.fail("预警日志删除失败");
        }
        return Result.success();
    }
    
    @SecurePostMapping(value = "/getWarningLogList", roles = "ROLE_ADMIN", permission = "warning-log:read")
    @Operation(summary = "获取预警日志列表")
    public Result<List<EduWarningLogVO>> getWarningLogList() {
        List<EduWarningLogVO> warningLogList = eduWarningLogService.getWarningLogList();
        return Result.success(warningLogList);
    }
}